import { app } from "../../../base";
import { ByteView } from "../../../app_base/module/net/byte/ByteView";
import { Attr } from "./ProtocolData";
import { cmd } from "../../../app_base/module/net/socket/BaseProtocolHelper";

function readArray(buffer: ByteView, aryType: string) {
    var len = buffer.readUint16();
    var temp = [];
    for (var i = 0; i < len; ++i) {
        if (aryType == "int") temp[i] = buffer.readInt32();
        else if (aryType == "uint") temp[i] = buffer.readUint32();
        else if (aryType == "double") temp[i] = buffer.readFloat64();
        else if (aryType == "short") temp[i] = buffer.readUint16();
        else if (aryType == "byte") temp[i] = buffer.readByte();
        else throw "error"
    }
    return temp;
}

function readArrayObj(buffer: ByteView, aryType) {
    var len = buffer.readUint16();
    var temp = [];
    for (var i = 0; i < len; ++i) {
        temp[i] = new aryType(buffer)
    }
    return temp;
}

/**
* @name ProtocolHandler
* @desc Socket协议接受解析类
* @author timoo
* @date 2022/12/24
* */
class ProtocolHandler {
    @cmd(923)
    SC_ON_LOGIN(buffer: ByteView): any[] {
        let r = readArrayObj(buffer, Attr);
        return r;
    }

}